.class public final Llt/farmis/libraries/externalgps/ExternalGPSThread;
.super Ljava/lang/Thread;
.source "ExternalGPSThread.kt"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;,
        Llt/farmis/libraries/externalgps/ExternalGPSThread$StatusListener;
    }
.end annotation


# instance fields
.field private volatile lastLocation:Llt/farmis/libraries/externalgps/GPSLocation;

.field private volatile lastLocationTime:J

.field private volatile locationUpdateListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;

.field private final mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

.field private final mNmeaParser:Llt/farmis/libraries/externalgps/nmea/NmeaParser;

.field private final mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

.field private volatile sleepInterval:J

.field private volatile statusListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$StatusListener;


# direct methods
.method public constructor <init>(Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;Llt/farmis/libraries/externalgps/nmea/NmeaParser;)V
    .locals 2

    const-string v0, "deviceProvider"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const-string v0, "nmeaParser"

    invoke-static {p2, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const-string v0, "EXT_GPS_THREAD"

    .line 11
    invoke-direct {p0, v0}, Ljava/lang/Thread;-><init>(Ljava/lang/String;)V

    .line 25
    new-instance v0, Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v1, 0x0

    invoke-direct {v0, v1}, Ljava/util/concurrent/atomic/AtomicBoolean;-><init>(Z)V

    iput-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    const-wide/16 v0, 0x12c

    .line 28
    iput-wide v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->sleepInterval:J

    .line 44
    iput-object p1, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    .line 45
    iput-object p2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mNmeaParser:Llt/farmis/libraries/externalgps/nmea/NmeaParser;

    .line 47
    new-instance p2, Llt/farmis/libraries/externalgps/ExternalGPSThread$1;

    invoke-direct {p2, p0}, Llt/farmis/libraries/externalgps/ExternalGPSThread$1;-><init>(Llt/farmis/libraries/externalgps/ExternalGPSThread;)V

    invoke-virtual {p1, p2}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->setStatusChangedListsener(Llt/farmis/libraries/externalgps/providers/NMEADeviceManager$OnStatusChangeListener;)V

    return-void
.end method


# virtual methods
.method public final disconnect()V
    .locals 2

    .line 109
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    invoke-virtual {v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->disconnect()V

    .line 110
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Ljava/util/concurrent/atomic/AtomicBoolean;->set(Z)V

    return-void
.end method

.method public final getMDeviceProvider()Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;
    .locals 1

    .line 21
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    return-object v0
.end method

.method protected final getMRunning()Ljava/util/concurrent/atomic/AtomicBoolean;
    .locals 1

    .line 25
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    return-object v0
.end method

.method public final getStatusListener()Llt/farmis/libraries/externalgps/ExternalGPSThread$StatusListener;
    .locals 1

    .line 34
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->statusListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$StatusListener;

    return-object v0
.end method

.method public run()V
    .locals 11

    .line 59
    invoke-super {p0}, Ljava/lang/Thread;->run()V

    const/16 v0, 0xa

    .line 60
    invoke-static {v0}, Landroid/os/Process;->setThreadPriority(I)V

    .line 62
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v1, 0x1

    invoke-virtual {v0, v1}, Ljava/util/concurrent/atomic/AtomicBoolean;->set(Z)V

    const-string v0, "NMEA"

    const-string v2, "StartedConnect"

    .line 63
    invoke-static {v0, v2}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 64
    iget-object v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    invoke-virtual {v2}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->connect()Z

    .line 66
    iget-object v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    invoke-virtual {v2}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->getStatus()Llt/farmis/libraries/externalgps/providers/Status;

    move-result-object v2

    sget-object v3, Llt/farmis/libraries/externalgps/providers/Status;->DISCONNECTED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-static {v2, v3}, Lkotlin/jvm/internal/Intrinsics;->areEqual(Ljava/lang/Object;Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_0

    const-string v1, "Conection failed"

    .line 67
    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    return-void

    .line 73
    :cond_0
    :goto_0
    :try_start_0
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-eqz v0, :cond_5

    .line 75
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    invoke-virtual {v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->getNewSample()Ljava/lang/String;

    move-result-object v0

    .line 78
    invoke-static {v0}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v2

    const-wide v3, 0x3fb999999999999aL    # 0.1

    if-eqz v2, :cond_2

    .line 79
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v5

    iget-wide v7, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocationTime:J

    sub-long/2addr v5, v7

    long-to-double v5, v5

    iget-wide v7, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->sleepInterval:J

    long-to-double v7, v7

    iget-wide v9, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->sleepInterval:J
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    long-to-double v9, v9

    invoke-static {v9, v10}, Ljava/lang/Double;->isNaN(D)Z

    mul-double v9, v9, v3

    invoke-static {v7, v8}, Ljava/lang/Double;->isNaN(D)Z

    sub-double/2addr v7, v9

    cmpl-double v0, v5, v7

    if-lez v0, :cond_0

    :try_start_1
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocation:Llt/farmis/libraries/externalgps/GPSLocation;

    if-eqz v0, :cond_0

    .line 81
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v2

    iput-wide v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocationTime:J

    .line 82
    iget-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->locationUpdateListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;

    if-eqz v0, :cond_0

    iget-object v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocation:Llt/farmis/libraries/externalgps/GPSLocation;

    if-eqz v2, :cond_1

    invoke-interface {v0, v2}, Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;->onLocationUpdate(Llt/farmis/libraries/externalgps/GPSLocation;)V

    goto :goto_0

    :cond_1
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    const/4 v0, 0x0

    throw v0

    .line 85
    :cond_2
    :try_start_2
    iget-object v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mNmeaParser:Llt/farmis/libraries/externalgps/nmea/NmeaParser;

    invoke-virtual {v2, v0}, Llt/farmis/libraries/externalgps/nmea/NmeaParser;->parse(Ljava/lang/String;)Llt/farmis/libraries/externalgps/GPSLocation;

    move-result-object v0

    .line 86
    iget-object v2, v0, Llt/farmis/libraries/externalgps/GPSLocation;->messageType:Ljava/lang/String;

    const-string v5, "GGA"

    invoke-static {v2, v5}, Lkotlin/jvm/internal/Intrinsics;->areEqual(Ljava/lang/Object;Ljava/lang/Object;)Z

    move-result v2

    if-eqz v2, :cond_0

    iget v2, v0, Llt/farmis/libraries/externalgps/GPSLocation;->lon:F

    const/4 v5, 0x0

    cmpg-float v2, v2, v5

    if-nez v2, :cond_3

    iget v2, v0, Llt/farmis/libraries/externalgps/GPSLocation;->lat:F

    cmpg-float v2, v2, v5

    if-eqz v2, :cond_0

    .line 89
    :cond_3
    iput-object v0, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocation:Llt/farmis/libraries/externalgps/GPSLocation;

    .line 90
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v5

    iget-wide v7, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocationTime:J

    sub-long/2addr v5, v7

    long-to-double v5, v5

    iget-wide v7, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->sleepInterval:J

    long-to-double v7, v7

    iget-wide v9, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->sleepInterval:J
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_0

    long-to-double v9, v9

    invoke-static {v9, v10}, Ljava/lang/Double;->isNaN(D)Z

    mul-double v9, v9, v3

    invoke-static {v7, v8}, Ljava/lang/Double;->isNaN(D)Z

    sub-double/2addr v7, v9

    cmpl-double v2, v5, v7

    if-lez v2, :cond_0

    .line 91
    :try_start_3
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v2

    iput-wide v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->lastLocationTime:J

    .line 92
    iget-object v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->locationUpdateListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;

    if-eqz v2, :cond_0

    const-string v3, "parsed"

    invoke-static {v0, v3}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    invoke-interface {v2, v0}, Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;->onLocationUpdate(Llt/farmis/libraries/externalgps/GPSLocation;)V
    :try_end_3
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_0

    goto/16 :goto_0

    :catch_0
    move-exception v0

    .line 99
    iget-object v2, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    invoke-virtual {v2}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->getStatus()Llt/farmis/libraries/externalgps/providers/Status;

    move-result-object v2

    sget-object v3, Llt/farmis/libraries/externalgps/providers/Status;->DISCONNECTED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-static {v2, v3}, Lkotlin/jvm/internal/Intrinsics;->areEqual(Ljava/lang/Object;Ljava/lang/Object;)Z

    move-result v2

    xor-int/2addr v1, v2

    if-eqz v1, :cond_4

    iget-object v1, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mDeviceProvider:Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;

    invoke-virtual {v1}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->disconnect()V

    .line 100
    :cond_4
    iget-object v1, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->mRunning:Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v2, 0x0

    invoke-virtual {v1, v2}, Ljava/util/concurrent/atomic/AtomicBoolean;->set(Z)V

    .line 101
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    :cond_5
    return-void
.end method

.method public final setLocationUpdateListener(Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;)V
    .locals 0

    .line 31
    iput-object p1, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->locationUpdateListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$LocationUpdateListener;

    return-void
.end method

.method public final setSleepInterval(J)V
    .locals 0

    .line 28
    iput-wide p1, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->sleepInterval:J

    return-void
.end method

.method public final setStatusListener(Llt/farmis/libraries/externalgps/ExternalGPSThread$StatusListener;)V
    .locals 0

    .line 34
    iput-object p1, p0, Llt/farmis/libraries/externalgps/ExternalGPSThread;->statusListener:Llt/farmis/libraries/externalgps/ExternalGPSThread$StatusListener;

    return-void
.end method
